import axios from "axios"
import { createHashHistory } from 'history'
import { message } from "antd"
let http = axios.create({
    baseURL: "/api",
    timeout: 1000 * 15,
    withCredentials: true
})


//请求拦截器

http.interceptors.request.use(config => {
    let token = sessionStorage.getItem('qf-token');
    if (token) {
        config.headers.authorization = token;
    }
    return config
})

//响应拦截

http.interceptors.response.use(response => {
    let data = response.data;
    // console.log(data)
    if (data.code === '1004' || data.code === "10022") {
        message.error('登入过期请重新登入,' + data.msg)
        window.location.href="/#/login"
        return Promise.reject(data.msg);
    }
    if (!data.state) {
        message.error(data.msg)
        return Promise.reject(data.msg)
    }
    return response
})


export default http
